<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace App\Controllers;

use SON\Controller\Action;

/**
 * Description of Login
 *
 * @author gilmario
 */
class Usuario extends Action {

    public function index() {

        if (!isset($this->view->menssagem)) {
            $this->view->menssagem = "";
        }
        $this->render("index");
    }

    public function adiciona() {
        if (isset($_POST['login']) && isset($_POST['senha'])) {
            $login = $_POST['login'];
            $senha = $_POST['senha'];
            if ($login == "") {
                $this->view->menssagem = "<div class=\"alert alert-warning\"> <button type=\"button\" class=\"close\" data-dismiss=\"alert\">×</button> Digite o nome" . "</div>";
                $this->index();
                return;
            }
            $dao = \SON\DI\Container::getClass("Usuario");
            $dao->adiciona($login, $senha);
            $this->view->menssagem = "<div class=\"alert alert-success\"> <button type=\"button\" class=\"close\" data-dismiss=\"alert\">×</button> usuario cadastrado" . "</div>";
            $this->render("index");
        } else {
            $this->index();
        }
    }

}
